package com.zhangji.practice.config;

import com.zhangji.practice.config.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description： TODO
 * @Date： 2021/8/31 8:23
 * @Author： ZhangJi
 * @Version： 1.0
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

  /**
   * 效果和IndexController一样，推荐使用这种形式
   * @param registry
   */
  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/index").setViewName("index");
    registry.addViewController("/hello").setViewName("index");
  }

  /**
   * 拦截器设置
   * @param registry
   */
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/login");
  }

}
